package me.shiqiang.im.conf;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cuishiqiang
 * @date 2018/8/21 下午1:44
 */
//@ConfigurationProperties(prefix = "datasource.elastic")
//@Configuration
public class ElasticDatasourceConfig {

    private String nodes;
    private String username;
    private String pwd;


    public String getNodes() {
        return nodes;
    }

    public void setNodes(String nodes) {
        this.nodes = nodes;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public Map<String,Integer> parse() {
        Map<String, Integer> map = new HashMap<>();
        for (String node : nodes.split(",")) {
            String[] hostAndPort = node.split(":");
            map.put(hostAndPort[0],Integer.parseInt(hostAndPort[1]));
        }
        return map;
    }
}
